<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\WxUserWithdrawal;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class WxUserWithdrawalController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new WxUserWithdrawal('user'), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('user.user_avatar', '用户头像')->image('', 50);
            $grid->column('user.user_name', '用户名');
            $grid->column('price');
            $grid->column('state')->using([0 => '待处理', 1 => '已处理', 2 => '异常'])->label([
                0 => 'success',
                1 => 'pink',
                2 => 'primary',
            ]);
            $grid->column('account_at');
            $grid->column('created_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
            // 禁用新增按钮
            $grid->disableCreateButton();
            // 禁用编辑按钮
            $grid->disableEditButton();
            // 禁用详情按钮
            $grid->disableViewButton();
            $grid->disableBatchDelete();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new WxUserWithdrawal(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('price');
            $show->field('state');
            $show->field('account_at');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new WxUserWithdrawal(), function (Form $form) {
            $form->display('id');
            $form->text('user_id');
            $form->text('price');
            $form->text('state');
            $form->text('account_at');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
